import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class, _class2;

import React from 'react';
import { Modal, Input, Form } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from "../../utils/intl";
var FormItem = Form.Item;
var formItemLayout = {
  labelCol: {
    sm: {
      span: 6
    }
  },
  wrapperCol: {
    sm: {
      span: 14
    }
  }
};
var TLModal = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(TLModal, _React$Component);

  var _super = _createSuper(TLModal);

  function TLModal() {
    _classCallCheck(this, TLModal);

    return _super.apply(this, arguments);
  }

  _createClass(TLModal, [{
    key: "saveAndClose",
    value: function saveAndClose() {
      var _this$props = this.props,
          _this$props$onOK = _this$props.onOK,
          onOK = _this$props$onOK === void 0 ? function (e) {
        return e;
      } : _this$props$onOK,
          form = _this$props.form;
      form.validateFields(function (err, fieldsValue) {
        if (!err) {
          onOK(fieldsValue);
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          modalVisible = _this$props2.modalVisible,
          onCancel = _this$props2.onCancel,
          form = _this$props2.form,
          list = _this$props2.list,
          label = _this$props2.label,
          _this$props2$width = _this$props2.width,
          width = _this$props2$width === void 0 ? '520px' : _this$props2$width,
          _this$props2$inputSiz = _this$props2.inputSize,
          inputSize = _this$props2$inputSiz === void 0 ? {} : _this$props2$inputSiz;
      var getFieldDecorator = form.getFieldDecorator;
      var _inputSize$zh = inputSize.zh,
          zh = _inputSize$zh === void 0 ? 60 : _inputSize$zh,
          _inputSize$en = inputSize.en,
          en = _inputSize$en === void 0 ? 120 : _inputSize$en;
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        title: label,
        width: width,
        visible: modalVisible,
        onCancel: onCancel,
        onOk: this.saveAndClose
      }, /*#__PURE__*/React.createElement(Form, null, list.map(function (item) {
        return /*#__PURE__*/React.createElement(FormItem, Object.assign({
          label: item.name,
          key: item.code
        }, formItemLayout), getFieldDecorator(item.code, {
          initialValue: item.value,
          rules: [{
            max: item.code === 'zh_CN' ? zh : en,
            message: intl.get('cpaas.common.validation.max', {
              max: item.code === 'zh_CN' ? zh : en
            })
          }]
        })( /*#__PURE__*/React.createElement(Input, null)));
      })));
    }
  }]);

  return TLModal;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "saveAndClose", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "saveAndClose"), _class2.prototype)), _class2)) || _class);
export { TLModal as default };